home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / computerjanitor / plugins / dpkg_dotfile_plugin.py < prev    next >
Encoding:
Python Source  |  2009-04-17  |  3.4 KB  |  87 lines

  1. # dpkg_dotfile_plugin.py - remove .dpkg-old/new files
  2. # Copyright (C) 2009  Canonical, Ltd.
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, version 3 of the License.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program.  If not, see <http://www.gnu.org/licenses/>.
  15.  
  16.  
  17. import os
  18.  
  19. import computerjanitor
  20. import computerjanitorapp
  21. _ = computerjanitorapp.setup_gettext()
  22.  
  23.  
  24. class DpkgDotfilePlugin(computerjanitor.Plugin):
  25.  
  26.     """Find .dpkg-old/new files.
  27.     
  28.     This plugin finds .dpkg-old and .dpkg-new files that dpkg creates
  29.     when it handles conffiles. They are typically in /etc, but
  30.     occasionally in some other locations, so we scan a list of directories
  31.     known to have conffiles. Any regular files with a .dpkg-old or
  32.     .dpkg-new suffix is added to the list.
  33.     
  34.     The find-conffiles-dirs script in the source code does this.
  35.     
  36.     """
  37.  
  38.     cruft_description = _("File was left on the disk by dpkg as part of "
  39.                           "its configuration file handling. If your computer "
  40.                           "works fine, you can remove it. You may want to "
  41.                           "compare it with the actual configuration file "
  42.                           "(the one without the .dpkg-old or .dpkg-new "
  43.                           "suffix). If unsure, don't remove the file.")
  44.  
  45.     def __init__(self):
  46.         # This is a list of directories that are known to contain, or have
  47.         # contained, conffiles in Ubuntu dapper, hardy, intrepid, or jaunty
  48.         # (as of Alpha 4). It should perhaps be updated periodically.
  49.         self.dirs = ["/etc",
  50.                      "/var/ax25",
  51.                      "/var/cache/roxen4",
  52.                      "/var/games",
  53.                      "/var/lib/crafty",
  54.                      "/var/lib/drac",
  55.                      "/var/lib/firebird2",
  56.                      "/var/lib/gnats",
  57.                      "/var/lib/leksbot",
  58.                      "/var/lib/linpopup",
  59.                      "/var/lib/lxr-cvs",
  60.                      "/var/lib/mason",
  61.                      "/var/lib/roxen4",
  62.                      "/var/lib/sysnews",
  63.                      "/var/list",
  64.                      "/var/spool/fcron",
  65.                      "/var/spool/hylafax/bin",
  66.                      "/var/yp"]
  67.  
  68.     def scan(self, dirname):
  69.         """Scan one directory for crufty files."""
  70.         list = []
  71.         for dirname, dirnames, filenames in os.walk(dirname):
  72.             filenames = [x for x in filenames 
  73.                          if x.endswith(".dpkg-old") or
  74.                             x.endswith(".dpkg-new")]
  75.             filenames = [os.path.join(dirname, x) for x in filenames]
  76.             filenames = [x for x in filenames 
  77.                          if os.path.isfile(x) and not os.path.islink(x)]
  78.             list += filenames
  79.         return list
  80.  
  81.     def get_cruft(self):
  82.         list = []
  83.         for dir in self.dirs:
  84.             list += self.scan(dir)
  85.         return [computerjanitor.FileCruft(x, self.cruft_description) 
  86.                 for x in list]
  87.